package com.taptech.doufu.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import androidx.recyclerview.widget.RecyclerView
import com.taptech.doufu.R
import com.taptech.doufu.model.user.NovelBean
import com.taptech.doufu.ui.activity.NovelDetailsActivity
import com.taptech.doufu.ui.activity.story.StoryDetailsActivity
import com.taptech.doufu.util.GlideUtil
import com.taptech.doufu.util.ScreenUtil
import kotlinx.android.synthetic.main.adapter_user_detail_latest_read.view.*

class UserDetailLatestReadAdapter(context: Context):BaseRecyclerAdappter<NovelBean,UserDetailLatestReadAdapter.ViewHolder>(context) {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(mContext).inflate(R.layout.adapter_user_detail_latest_read,null)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        val item = dataList[position]
        val params = RelativeLayout.LayoutParams(ScreenUtil.dip2px(mContext,80f),ScreenUtil.dip2px(mContext,107f))
        params.topMargin = ScreenUtil.dip2px(mContext,10f)
        when (position) {
            0 -> {
                params.leftMargin = ScreenUtil.dip2px(mContext,27f)
                params.rightMargin = 0
            }
            dataList.size-1 -> {
                params.leftMargin = ScreenUtil.dip2px(mContext,15f)
                params.rightMargin = ScreenUtil.dip2px(mContext,27f)
            }
            else -> {
                params.leftMargin = ScreenUtil.dip2px(mContext,15f)
                params.rightMargin = 0
            }
        }
        holder.itemView.ivCover.layoutParams = params
        GlideUtil.displayRoundImage(mContext, holder.itemView.ivCover, item.with_image, 5,R.drawable.img_default_loading_l)
        holder.itemView.tvTitle.text = item.topic_title
        holder.itemView.setOnClickListener {
            if (item.single_page == 1) {
                StoryDetailsActivity.startActivity(mContext,item.id)
            }else{
                NovelDetailsActivity.startActivity(mContext,item.id)
            }
        }
    }

    class ViewHolder(view:View): RecyclerView.ViewHolder(view)
}